package entity;

import java.time.LocalDate;
import java.time.Period;

//学生类
public class Student {
    //学号,姓名,年龄,专业,入学日期
    private String studentID;
    private String name;
    private int age;
    private String major;
    private LocalDate enrollDate;

    //构造函数
    public Student(String studentID, String name, int age, String major, LocalDate enrollDate) {
        this.studentID = studentID;
        this.name = name;
        this.age = age;
        this.major = major;
        this.enrollDate = enrollDate;
    }

    //get和set方法
    public String getStudentID() {
        return studentID;
    }
    public void setStudentID(String studentID) {
        this.studentID = studentID;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getMajor() {
        return major;
    }
    public void setMajor(String major) {
        this.major = major;
    }

    public LocalDate getEnrollDate() {
        return enrollDate;
    }

    public void setEnrollDate(LocalDate enrollDate) {
        this.enrollDate = enrollDate;
    }
    
    /**
     * 获取学制（根据入学日期计算）
     */
    public int getStudyYears() {
        if (enrollDate != null) {
            LocalDate now = LocalDate.now();
            return Period.between(enrollDate, now).getYears();
        }
        return 0;
    }
    
    /**
     * 获取年级（根据入学日期计算）
     */
    public String getGrade() {
        if (enrollDate != null) {
            int year = enrollDate.getYear();
            int nowYear = LocalDate.now().getYear();
            int grade = nowYear - year + 1;
            if (grade <= 4) {
                switch (grade) {
                    case 1: return "大一";
                    case 2: return "大二";
                    case 3: return "大三";
                    case 4: return "大四";
                    default: return "其他";
                }
            }
        }
        return "未知";
    }

    @Override
    public String toString() {
        return "{" +
                "学号='" + studentID + '\'' +
                ", 姓名='" + name + '\'' +
                ", 年龄=" + age +
                ", 专业='" + major + '\'' +
                ", 入学日期=" + enrollDate +
                ", 年级='" + getGrade() + '\'' +
                '}';
    }
}